package com.campus.web;


import com.campus.web.vo.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @desc:  全局捕获Controller层的出现的异常。
 * @author: Ping
 * @date: 2024/10/22 17:04
 */

@ControllerAdvice
@Slf4j
public class WebExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseResult<String> handleAppException(Exception e, HttpServletRequest request) {
        log.info(e.getMessage());
        return ResponseResult.error(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }

}
